home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Texteditors / Origami / Sources / src / origami / tok2h.awk < prev    next >
Encoding:
AWK Script  |  1996-09-27  |  3.5 KB  |  108 lines

  1. BEGIN {
  2.   #{{{}}}
  3. #  {{{  print auto-gen-mark
  4.   print("/* This file is generated automatically by awk -f tok2h.awk */\n/* containing permission and execution-level information for OCL tokens */")
  5. #  }}}
  6. #  {{{  print permission constants
  7.   print("/*{{{  permissons*/")
  8. #  {{{  print mask constants
  9.   print("/*{{{  bits and mask*/")
  10.   print("#define KTI_NONE\t0\t/* no permissions\t*/")
  11.   print("#define KTI_B\t\t1\t/* browse key\t\t*/")
  12.   print("#define KTI_F\t\t2\t/* fieldedit key\t*/")
  13.   print("#define KTI_S\t\t4\t/* screen key - folding\t*/")
  14.   print("#define KTI_P\t\t8\t/* prompt key\t\t*/")
  15.   print("#define KT_LG\t\t4\t/* number of used bits\t*/")
  16.   print("/*}}}  */")
  17. #  }}}
  18. #  {{{  print combined masks
  19.   print("/*{{{  combined*/")
  20.   print("#define KT_DUMMY\t0\t/* not used\t*/")
  21.   print("")
  22.   print("#define KT_NONE\t\tKTI_NONE")
  23.   print("#define KT_B\t\tKTI_B")
  24.   print("#define KT_F\t\tKTI_F")
  25.   print("#define KT_S\t\tKTI_S")
  26.   print("#define KT_P\t\tKTI_P")
  27.   print("#define KT_PSFB\t\t(KTI_P|KTI_S|KTI_F|KTI_B)")
  28.   print("#define KT_SFB\t\t(KTI_S|KTI_F|KTI_B)")
  29.   print("#define KT_PFB\t\t(KTI_P|KTI_F|KTI_B)")
  30.   print("#define KT_PSB\t\t(KTI_P|KTI_S|KTI_B)")
  31.   print("#define KT_PSF\t\t(KTI_P|KTI_S|KTI_F)")
  32.   print("#define KT_FB\t\t(KTI_F|KTI_B)")
  33.   print("#define KT_PB\t\t(KTI_P|KTI_B)")
  34.   print("#define KT_PS\t\t(KTI_P|KTI_S)")
  35.   print("#define KT_SF\t\t(KTI_S|KTI_F)")
  36.   print("#define KT_SB\t\t(KTI_S|KTI_B)")
  37.   print("#define KT_PF\t\t(KTI_P|KTI_F)")
  38.   print("/*}}}  */")
  39. #  }}}
  40.   print("/*}}}  */")
  41. #  }}}
  42. #  {{{  print type definition
  43.   print("/*{{{  types*/")
  44.   print("typedef enum")
  45.   print(" { COM=0,\t/* simple command\t\t\t*/")
  46.   print("   COM_C,\t/* command with 1 char argument\t\t*/")
  47.   print("   COM_I,\t/* command with 1 int argument\t\t*/")
  48.   print("   COM_A,\t/* command with a adress\t\t*/")
  49.   print("   COM_II,\t/* command with 2 int arguments\t\t*/")
  50.   print("   COM_P,\t/* command with a prompt\t\t*/")
  51.   print("   COM_IP,\t/* command with 1 int and prompt\t*/")
  52.   print("   COM_IIP\t/* command with 2 int and prompt\t*/")
  53.   print(" } COM_TYPES;")
  54.   print("/*}}}  */")
  55. #  }}}
  56.   print("/*{{{  datalist*/")
  57. #  {{{  P_T_MERGE
  58.   print("#define P_T_MERGE(p,c) (p|(c<<KT_LG))")
  59. #  }}}
  60. #  {{{  GET_T
  61.   print("#define GET_T(x) \\")
  62.   print("  (((x<=O_NOP)||(x>=O_EXE_MACRO))           \\")
  63.   print("    ? COM                                   \\")
  64.   print("    : (COM_TYPES)(key_info[x-O_NOP]>>KT_LG))")
  65.   print("")
  66. #  }}}
  67.   printf("private char const key_info[] =\n { P_T_MERGE(KT_PSFB,COM)  \t/* O_NOP */")
  68. #  {{{  init fixed cmd arg range
  69.   cmd_range=8
  70. #  }}}
  71. }
  72. #{{{  set fixed cmd command range
  73. /^#define +FIXED_COMMAND_RANGE/ {
  74.   cmd_range=$3
  75.   next
  76. }
  77. #}}}
  78. #{{{  set types for command and fixed command
  79. $3=="COM" || $3=="COM_I" || $3=="COM_II" || $3=="COM_P" || $3=="COM_IP" || $3=="COM_IIP" || $3=="COM_C" { typ=$3;fix_typ="" }
  80. $3=="COM_A" { typ="COM_A";fix_typ="COM" }
  81. $3=="COM_ID" { typ="COM_II";fix_typ="COM_I" }
  82. $3=="COM_D" { typ="COM_I";fix_typ="COM" }
  83. #}}}
  84. #{{{  print command type and permissions
  85. substr($1,1,1)!="#" && $3!="OCL-KEY" && $3!="OPP-KEY" {
  86. #  {{{  get permission, strip 's'
  87.   p="KT_"
  88.   i=4
  89.   while (i<=length($2)) {
  90.     if (substr($2,i,1)!="s") p=p substr($2,i,1)
  91.     i++
  92.   }
  93.   if (p=="KT_") p="KT_NONE"
  94. #  }}}
  95.   if (fix_typ!="") {
  96.     for (i=cmd_range;i>0;i--)
  97.       printf(",\n   P_T_MERGE(%s,%s)  \t/* %s */",p,fix_typ,$1"_M"i)
  98.     for (i=0;i<=cmd_range;i++)
  99.       printf(",\n   P_T_MERGE(%s,%s)  \t/* %s */",p,fix_typ,$1"_"i)
  100.   }
  101.   printf(",\n   P_T_MERGE(%s,%s)  \t/* %s */",p,typ,$1)
  102. }
  103. #}}}
  104. END {
  105.   printf("\n };\n")
  106.   print("/*}}}  */")
  107. }
  108.